home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / favori / favorit1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  17.4 KB  |  492 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H0080C0FF&
  4.    Caption         =   "Favorite Program Launcher"
  5.    ClientHeight    =   3990
  6.    ClientLeft      =   375
  7.    ClientTop       =   2085
  8.    ClientWidth     =   7845
  9.    FontBold        =   -1  'True
  10.    FontItalic      =   0   'False
  11.    FontName        =   "Courier"
  12.    FontSize        =   9.75
  13.    FontStrikethru  =   0   'False
  14.    FontUnderline   =   0   'False
  15.    ForeColor       =   &H00000000&
  16.    Height          =   4680
  17.    Icon            =   FAVORIT1.FRX:0000
  18.    Left            =   315
  19.    LinkMode        =   1  'Source
  20.    LinkTopic       =   "Form1"
  21.    ScaleHeight     =   3990
  22.    ScaleWidth      =   7845
  23.    Top             =   1455
  24.    Width           =   7965
  25.    Begin CommandButton DosButton 
  26.       Caption         =   "Shell to DOS"
  27.       Height          =   375
  28.       Left            =   240
  29.       TabIndex        =   2
  30.       Top             =   3240
  31.       Width           =   2895
  32.    End
  33.    Begin CommandButton CancelButton 
  34.       Caption         =   "Cancel"
  35.       Height          =   495
  36.       Left            =   6720
  37.       TabIndex        =   7
  38.       Top             =   3120
  39.       Visible         =   0   'False
  40.       Width           =   855
  41.    End
  42.    Begin CommandButton OKButton 
  43.       Caption         =   "OK"
  44.       Height          =   495
  45.       Left            =   5280
  46.       TabIndex        =   6
  47.       Top             =   3120
  48.       Visible         =   0   'False
  49.       Width           =   855
  50.    End
  51.    Begin CheckBox Check1 
  52.       BackColor       =   &H0080C0FF&
  53.       Caption         =   "Check1"
  54.       Height          =   255
  55.       Left            =   720
  56.       TabIndex        =   1
  57.       Top             =   3000
  58.       Width           =   255
  59.    End
  60.    Begin TextBox CommandlineName 
  61.       BackColor       =   &H00E0FFFF&
  62.       FontBold        =   -1  'True
  63.       FontItalic      =   0   'False
  64.       FontName        =   "MS Sans Serif"
  65.       FontSize        =   9.75
  66.       FontStrikethru  =   0   'False
  67.       FontUnderline   =   0   'False
  68.       Height          =   375
  69.       Left            =   5280
  70.       TabIndex        =   5
  71.       Top             =   2040
  72.       Visible         =   0   'False
  73.       Width           =   2295
  74.    End
  75.    Begin CommandButton BrowseButton 
  76.       BackColor       =   &H00C0C0C0&
  77.       Caption         =   "Pick A File"
  78.       Height          =   495
  79.       Left            =   6000
  80.       TabIndex        =   4
  81.       Top             =   960
  82.       Width           =   1095
  83.    End
  84.    Begin ListBox List1 
  85.       BackColor       =   &H00E0FFFF&
  86.       FontBold        =   -1  'True
  87.       FontItalic      =   0   'False
  88.       FontName        =   "MS Sans Serif"
  89.       FontSize        =   12
  90.       FontStrikethru  =   0   'False
  91.       FontUnderline   =   0   'False
  92.       Height          =   2130
  93.       Left            =   600
  94.       Sorted          =   -1  'True
  95.       TabIndex        =   0
  96.       Top             =   720
  97.       Width           =   2295
  98.    End
  99.    Begin TextBox PetName 
  100.       BackColor       =   &H00E0FFFF&
  101.       FontBold        =   -1  'True
  102.       FontItalic      =   0   'False
  103.       FontName        =   "MS Sans Serif"
  104.       FontSize        =   12
  105.       FontStrikethru  =   0   'False
  106.       FontUnderline   =   0   'False
  107.       Height          =   420
  108.       Left            =   5400
  109.       TabIndex        =   3
  110.       Top             =   240
  111.       Visible         =   0   'False
  112.       Width           =   1935
  113.    End
  114.    Begin PictureBox Picture1 
  115.       Height          =   495
  116.       Left            =   1560
  117.       Picture         =   FAVORIT1.FRX:0302
  118.       ScaleHeight     =   465
  119.       ScaleWidth      =   465
  120.       TabIndex        =   11
  121.       Top             =   120
  122.       Width           =   495
  123.    End
  124.    Begin Label Checklabel 
  125.       BackColor       =   &H0080C0FF&
  126.       Caption         =   "Minimize on Launch"
  127.       Height          =   255
  128.       Left            =   1080
  129.       TabIndex        =   8
  130.       Top             =   3000
  131.       Width           =   1815
  132.    End
  133.    Begin Label CommandlineLabel 
  134.       BackColor       =   &H0080C0FF&
  135.       Caption         =   "Command Line"
  136.       Height          =   255
  137.       Left            =   3960
  138.       TabIndex        =   10
  139.       Top             =   2160
  140.       Visible         =   0   'False
  141.       Width           =   1455
  142.    End
  143.    Begin Label Filenamelabel 
  144.       BackColor       =   &H00C0E0FF&
  145.       BorderStyle     =   1  'Fixed Single
  146.       Height          =   255
  147.       Left            =   4560
  148.       TabIndex        =   12
  149.       Top             =   1560
  150.       Width           =   3255
  151.    End
  152.    Begin Label PetnameLabel 
  153.       Alignment       =   2  'Center
  154.       BackColor       =   &H0080C0FF&
  155.       Caption         =   "Pet Name"
  156.       Height          =   255
  157.       Left            =   4080
  158.       TabIndex        =   9
  159.       Top             =   480
  160.       Visible         =   0   'False
  161.       Width           =   1095
  162.    End
  163.    Begin Menu AddMenu 
  164.       Caption         =   "&Add"
  165.    End
  166.    Begin Menu ChangeMenu 
  167.       Caption         =   "&Change"
  168.    End
  169.    Begin Menu DeleteMenu 
  170.       Caption         =   "&Delete"
  171.    End
  172.    Begin Menu UndeleteMenu 
  173.       Caption         =   "&Undelete"
  174.    End
  175.    Begin Menu HelpMenu 
  176.       Caption         =   "&Help"
  177.       Begin Menu HelpKey 
  178.          Shortcut        =   {F1}
  179.          Visible         =   0   'False
  180.       End
  181.    End
  182.    Begin Menu AboutMenu 
  183.       Caption         =   "&About"
  184.    End
  185. 'GLOBALS TO FORM
  186. Dim MAINTSWITCH As String       'tells if "A"dd or "C"hange
  187. Dim TRUEFALSE As Integer        'used in subrte to swap visibility
  188. Dim FIRSTSWITCH As String       'used at load time for initialization
  189. Dim INIDATA As String           'work area
  190. Dim DELETEDITEMS(100)  As String  'array saves prior deletes
  191.                                   '  for UNDELETE menu item
  192. ' display the "About" menu (Form3) when menu item clicked
  193. Sub AboutMenu_Click ()
  194.  Load Form3                  'load the form
  195.  Form3.visible = True        'make it visible
  196.  Form3.COMMAND1.SetFocus     'change focus to forms "OK" button
  197. End Sub
  198. 'adds and changes to list of programs and FAVORITE.INI file
  199. 'are processed here
  200. Sub add_to_list ()
  201.  If MAINTSWITCH = "C" Then     'came here by "C"hange
  202.   WORKITEM% = List1.listindex  'find item in list1 array
  203.  End If
  204.  If LTrim$(RTrim$(Petname.text)) = "" Then
  205.     Beep                     'user didn't enter PETNAME
  206.     response% = MsgBox("Enter information in Pet Name or Cancel your change.", 64, "Message")
  207.     Petname.SetFocus         'put cursor back at PETNAME
  208.     Exit Sub
  209.  ElseIf LTrim$(RTrim$(RUNFILENAME$)) = "" Then
  210.     Beep                      'user didn't enter PROGRAMNAME
  211.     response% = MsgBox("Enter program name information or Cancel the change.", 64, "Message")
  212.     Commandlinename.SetFocus  'put cursor back at PROGRAMNAME
  213.     Exit Sub
  214.  End If
  215.  WORK% = Len(Petname.text)    'align the entered data so it
  216.  If WORK% >= 20 Then          'can be placed in list1 and .INI file
  217.     DATAWORK$ = UCase$(Left$(Petname.text, 20))
  218.  Else
  219.     DATAWORK$ = UCase$(Petname.text + String$(20 - WORK%, " "))
  220.  End If
  221.  WORK% = Len(RUNFILENAME$)
  222.     DATAWORK$ = DATAWORK$ + String$(10, " ") + RUNFILENAME$ + String$(50 - WORK%, " ")
  223.  WORK% = Len(Commandlinename.text) 'align COMMANDLINE
  224.  If WORK% >= 32 Then
  225.      DATAWORK$ = DATAWORK$ + Left$(Commandlinename.text, 32)
  226.  Else
  227.      DATAWORK$ = DATAWORK$ + Commandlinename.text + String$(32 - WORK%, " ")
  228.  End If
  229.  If MAINTSWITCH = "C" Then     'if change, remove old item from List1
  230.      List1.RemoveItem WORKITEM%
  231.  End If
  232. MAINTSWITCH = ""          'not needed any further, clear
  233. List1.AddItem DATAWORK$   'add to list1
  234. Writefile                 'go to subrte to write FAVORITE.INI file
  235. Make_Boxes_Visible (False) 'hide the right side boxes & buttons
  236. Clear_the_fields          'clear the box texts
  237. End Sub
  238. Sub AddCtl_Click ()
  239.  List1.visible = True        'make right side of form visible
  240.  Make_Boxes_Visible (True)
  241. End Sub
  242. ' invoked when "Add" is clicked
  243. Sub AddMenu_Click ()
  244.  Clear_the_fields
  245.  Make_Boxes_Visible (True)     'sub to make right side of form
  246.  MAINTSWITCH = "A"             'visible
  247.  Petname.SetFocus              'move cursor to PETNAME field
  248.  End Sub
  249. Sub BrowseButton_Click ()
  250.  Load form4
  251.  form4.visible = True
  252. End Sub
  253. ' user CANCELS a change or ADD transaction
  254. Sub CancelButton_Click ()
  255.  Clear_the_fields             'clear any entered data
  256.  Make_Boxes_Visible (False)     'sub to shrink form
  257. End Sub
  258. ' invoked when user selects CHANGE from menu
  259. Sub ChangeMenu_Click ()
  260. If List1.listcount < 1 Or List1.listindex < 0 Then
  261.   Beep               'nothing in list1 array to change
  262.   If List1.listcount > 0 Then   'tell them what to do
  263.     response% = MsgBox("Click an item in the list first.", 64, "Message")
  264.   Else
  265.     response% = MsgBox("No items in list.", 64, "Message")
  266.   End If
  267.   Exit Sub
  268. End If
  269.  Make_Boxes_Visible (True)     'make form wide
  270.  MAINTSWITCH = "C"             'tell the world we are doing a
  271.                                'change transaction
  272. 'move data from item in List1 array to text boxes
  273. Petname.text = Left$(List1.list(List1.listindex), 20)
  274. RUNFILENAME$ = Mid$(List1.list(List1.listindex), 31, 50)
  275. Filenamelabel.caption = RUNFILENAME$ + String$(50, " ")
  276. Commandlinename.text = Right$(List1.list(List1.listindex), 32)
  277. Petname.SetFocus       'move cursor to PETNAME field
  278. End Sub
  279. Sub Clear_the_fields ()
  280.  Petname.text = ""             'clear text box data
  281.  Filenamelabel.caption = ""    'clear the current file name
  282.  RUNFILENAME$ = ""             'clear the chosen name
  283.  Commandlinename.text = ""     'clear the command line
  284. End Sub
  285. ' edit the field when user leaves field
  286. Sub CommandlineName_LostFocus ()
  287.  Commandlinename.text = LTrim$(RTrim$(Commandlinename.text))
  288. End Sub
  289. 'user selected DELETE from menu.  Delete the item from the
  290. 'List1 array and rewrite the FAVORITE.INI file.
  291. Sub DeleteMenu_Click ()
  292.  form1.width = 3915            'make form narrow
  293.  Clear_the_fields              'clear text boxes
  294.  If List1.listcount < 1 Or List1.listindex < 0 Then
  295.    Beep                         'check for no items in list
  296.    If List1.listcount < 1 Then
  297.     response% = MsgBox("There are no items in list.", 64, "Message")
  298.    Else
  299.     response% = MsgBox("Click an item in the list.", 64, "Message")
  300.    End If
  301.  Exit Sub         'leave this sub if nothing in List1 array
  302.  End If
  303.  WORK% = 49 'button matrix for Msgbox
  304.  response% = MsgBox("Delete " + LTrim$(RTrim$(Left$(List1.list(List1.listindex), 20))) + " ?", WORK%, "Warning")
  305.  If response% = 2 Then        'user chose CANCEL button
  306.    Exit Sub
  307.  End If
  308.  WORK% = List1.listindex      'item in List1 array to delete
  309.   For I = 0 To 999            'this loop adds to array of deleted
  310.     On Error GoTo noitem      'items this session for possible undeletes
  311.     If Len(LTrim$(RTrim$(DELETEDITEMS(I)))) < 5 Then
  312.       Exit For
  313.     End If
  314.   Next I
  315. noitem2:
  316.   DELETEDITEMS(I) = List1.list(List1.listindex)  'add to deleted items array
  317. List1.RemoveItem WORK%   'remove from list1 array
  318. MAINTSWITCH = ""
  319.  If List1.listcount = 0 Then   'nothing in list
  320.     On Error GoTo killerror    'delete any existing FAVORITE.INI file
  321.  Kill "favorite.ini"
  322.  Exit Sub
  323. noitem:
  324. Resume noitem2
  325. killerror:
  326. Resume killerror2
  327. killerror2:
  328. Exit Sub
  329. Writefile              'go to routine to write the file out
  330. End If
  331. End Sub
  332. Sub DosButton_Click ()
  333.  On Error GoTo shellerror
  334.  x = Shell("command.com", 1)
  335.  Exit Sub
  336. shellerror:
  337.  Resume shellerror2
  338. shellerror2:
  339. response% = MsgBox("Couldn't execute COMMAND.COM. The probable problems are that COMMAND.COM is not in your path or your Window's TEMP disk is full.", 16)
  340. End Sub
  341. Sub form_load ()
  342.  'VB will begin here.  Use FIRSTSWITCH as the program
  343.  'initialization trigger.
  344.  If FIRSTSWITCH = "" Then
  345.     FIRSTSWITCH = "X"        'turn switch on so routine
  346.                              'won't be used again
  347.     form1.width = 3915
  348.     On Error GoTo NoIniFile   'if INI file never created
  349.                              '(VB still needs GOTO's)
  350.     Open "favorite.ini" For Input As #1
  351.     Close #1                 ' File exists
  352.     ReadINIFile              'go read INI file
  353.     Exit Sub
  354.  Else
  355.     Exit Sub
  356.  End If
  357. NoIniFile:                   'INI file doesn't exist
  358.     Resume NoIniFile2
  359. NoIniFile2:
  360. End Sub
  361. ' user chose HELP from menu
  362. Sub helpkey_click ()
  363.  Load FORM2                'load the help form into memory
  364.  FORM2.visible = True      'make it visible
  365.  FORM2.helpbutton.SetFocus  'put cursor on "OK" button
  366. End Sub
  367. 'user chose HELP key
  368. Sub HelpMenu_Click ()
  369.  helpkey_click
  370. End Sub
  371. ' user single-clicked to hilight list1 item he wanted
  372. Sub List1_Click ()
  373. Clear_the_fields           'clear text boxes
  374. form1.width = 3915          'make form narrow
  375. End Sub
  376. ' DBL-clicking an item in the list causes it to run through
  377. ' WINDOW'S PROGRAM MANAGER
  378. Sub List1_DblClick ()
  379. If List1.listcount < 1 Then   'must be at least 1 item in list
  380.  Beep
  381.  Exit Sub
  382. End If
  383. WORK% = List1.listindex       'pointer to item in list1
  384. 'see if "Minimize on Run" box is checked, if so minimize to icon
  385. If check1.value = 1 Then form1.windowstate = 1
  386. 'prepare SHELL instruction parameters -- program | parameters
  387. shellitem$ = LTrim$(RTrim$(Mid$(List1.list(WORK%), 31, 50)))
  388. shellitem$ = shellitem$ + " "
  389. shellitem$ = shellitem$ + LTrim$(RTrim$(Right$(List1.list(WORK%), 32)))
  390. savecaption$ = form1.caption   'save the caption & put temp one in
  391. form1.caption = "Run " + LTrim$(Left$(List1.list(WORK%), 20))
  392. On Error GoTo filenotfound  'in case parameters not ok
  393. x = Shell(shellitem$, 1)  'shell to program manager
  394. form1.caption = savecaption$
  395. Exit Sub
  396. filenotfound:
  397. Resume filenotfound2
  398. filenotfound2:       'not found dialog button
  399. msg$ = "The program name or suffix you entered"
  400. msg$ = msg$ + " will not call your "
  401. msg$ = msg$ + "program from Window's Program Manager."
  402. msg$ = msg$ + " Please  "
  403. msg$ = msg$ + "click CHANGE to review."
  404. response% = MsgBox(msg$, 16, LTrim$(RTrim$(Mid$(List1.list(List1.listindex), 1, 20))))
  405. form1.caption = savecaption$
  406. End Sub
  407. 'user passes value in TRUEFALSE variable to tell whether to
  408. 'make form's right side visible or to shrink. TRUE = make
  409. 'right side visible.  FALSE  = shrink screen to left.
  410. Sub Make_Boxes_Visible (TRUEFALSE)
  411. If form1.windowstate = 0 Then     'check to see that user has
  412.                                   'not minimized form
  413.  If TRUEFALSE = True Then
  414.     form1.width = 8400             'wide with
  415.  Else
  416.     form1.width = 3915             'narrow width
  417.  End If
  418. End If
  419.  PetnameLabel.visible = TRUEFALSE     'make labels, boxes and
  420.  CommandlineLabel.visible = TRUEFALSE 'visible or invisible
  421.  Petname.visible = TRUEFALSE
  422.  browsebutton.visible = TRUEFALSE
  423.  Commandlinename.visible = TRUEFALSE
  424.  OKButton.visible = TRUEFALSE
  425.  CancelButton.visible = TRUEFALSE
  426.  Filenamelabel.visible = TRUEFALSE
  427. End Sub
  428. ' user chooses "OK" after ADD or CHANGE transaction
  429. Sub OKButton_Click ()
  430.  add_to_list             'routine to add item to List1 array
  431. End Sub                  'and FAVORITE.INI file
  432. ' aligns text when user leaves text box
  433. Sub PetName_LostFocus ()
  434.   Petname.text = LTrim$(RTrim$(Petname.text))
  435. End Sub
  436. 'read the FAVORITE.INI file and build list1
  437. Sub ReadINIFile ()
  438.  Open "favorite.ini" For Input As #1
  439.  WORK% = LOF(1)
  440.  If WORK% < 5 Then            'test to see if null file or not
  441.  Close #1                     'is null file
  442.  Kill "favorite.ini"          'delete the file
  443.  Exit Sub                     'leave, no input
  444.  End If
  445.  On Error GoTo EndofIniFile    'force error when end of file
  446.  For I = 0 To 999                    'Read all possible data
  447.  Line Input #1, INIDATA              'Read one line of file
  448.  List1.list(I) = INIDATA             'put file record in list1
  449.  Next I
  450. EndofIniFile:                   'got here at end of file
  451. Resume endofinifile2
  452. endofinifile2:
  453.  Close #1
  454. End Sub
  455. ' user can undelete as many items as have been deleted this
  456. 'session by clicking on UNDELETE.  This subroutine removes them
  457. 'from the saved array and replaces them back into the List1 array
  458. Sub UndeleteMenu_Click ()
  459.  If Len(LTrim$(RTrim$(DELETEDITEMS(0)))) < 5 Then
  460.     Beep          'check to see if anything saved
  461.     response% = MsgBox("There are no items to undelete.", 64, "Message")
  462.     Exit Sub
  463.  End If
  464. 'pull the last deleted item from the array
  465. 'and place back into list, deleting it from the saved array
  466.  For I = 99 To 0 Step -1
  467.    If Len(LTrim$(RTrim$(DELETEDITEMS(I)))) > 5 Then
  468.      List1.AddItem DELETEDITEMS(I)    'add it back to List1 array
  469.      DELETEDITEMS(I) = ""
  470.      Exit For
  471.    End If
  472.    Next I
  473.    Writefile        'goto sub to write the FAVORITE.INI file
  474. End Sub
  475. 'sub to write the FAVORITE.INI file after successful
  476. 'change or add transaction
  477. Sub Writefile ()
  478. Open "favorite.ini" For Output As #1
  479.  On Error GoTo writeclose           'force error at end of list1 array
  480.  WORK% = List1.listcount            'find out how many items in list1 array
  481.  For I = 0 To WORK% - 1              'loop thru array
  482.   INIDATA = List1.list(I)            'move to output form-global
  483.   Print #1, INIDATA                  'write the record
  484.  Next I
  485.  Close #1
  486.  Exit Sub
  487. writeclose:                      'error trap
  488. Resume writeclose2
  489. writeclose2:
  490. Close #1
  491. End Sub
  492.